# Maintainer: Ray Donnelly <mingw.android@gmail.com>
# Contributor: Renato Silva <br.renatosilva@gmail.com>

_realname='pywin32'
url='https://sourceforge.net/projects/pywin32'
pkgdesc='Python for Windows Extensions (mingw-w64)'
license=('PSF')
arch=('any')
pkgver=219
pkgrel=1
makedepends=(${MINGW_PACKAGE_PREFIX}-python2 ${MINGW_PACKAGE_PREFIX}-python3 rsync)
pkgbase=mingw-w64-python-${_realname}
pkgname=(${MINGW_PACKAGE_PREFIX}-python2-${_realname} ${MINGW_PACKAGE_PREFIX}-python3-${_realname})
source=("https://prdownloads.sourceforge.net/${_realname}/${_realname}-${pkgver}.zip"
        001-compile-and-setup-fixes.patch)
sha256sums=('30c3dbcd45d0c126ad9102d4bbcdeb6b9846869d0b1721faa4f8c9b563ccdb49'
            '6968c607e1768fd2a78aa5aa8bf7238606638aec81e8844f840eabcf2a6da092')

prepare() {
    cd "${srcdir}/${_realname}-${pkgver}"
    patch -p1 < "${startdir}"/001-compile-and-setup-fixes.patch
}

build() {
    for _python in python2 python3; do
        msg2 "Synchronizing ${_python} build directory"
        rsync --recursive --times "${srcdir}/${_realname}-${pkgver}"/* "${srcdir}/build-${_python}-${CARCH}-${_realname}-${pkgver}"
        cd "${srcdir}/build-${_python}-${CARCH}-${_realname}-${pkgver}"
        LIB="${MINGW_PREFIX}/lib:${MINGW_PREFIX}/${CARCH}-w64-mingw32/lib" \
        INCLUDE="${MINGW_PREFIX}/include:${MINGW_PREFIX}/${CARCH}-w64-mingw32/include" \
        ${MINGW_PREFIX}/bin/${_python} setup.py build --compiler=mingw32
    done
}

_package() {
    depends=(${MINGW_PACKAGE_PREFIX}-${_python}-setuptools)
    cd "${srcdir}/build-${_python}-${CARCH}-${_realname}-${pkgver}"
    DISTUTILS_DEBUG=1 \
    MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
    ${MINGW_PREFIX}/bin/${_python} setup.py install \
        --prefix=${MINGW_PREFIX} \
        --root="${pkgdir}" \
        --optimize=1
}

package_mingw-w64-i686-python2-pywin32()   { _python=python2 _package; }
package_mingw-w64-i686-python3-pywin32()   { _python=python3 _package; }
package_mingw-w64-x86_64-python2-pywin32() { _python=python2 _package; }
package_mingw-w64-x86_64-python3-pywin32() { _python=python3 _package; }
